<template>
  <div class="prize-form-container">
    <el-card class="form-card" style="height: 800px">
      <div slot="header" class="clearfix">
        <div class="breadcrumb">
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">
              <i class="el-icon-s-promotion"></i> 首页
            </el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/home/prize-list' }">
              <i class="el-icon-s-promotion"></i> 奖品列表
            </el-breadcrumb-item>
            <el-breadcrumb-item>奖品新建</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
      </div>

      <el-form :model="form" label-width="100px" class="prize-form">
        <el-form-item label="奖品名称">
          <el-input v-model="form.name" placeholder="请输入奖品名称"></el-input>
        </el-form-item>
        <el-form-item label="奖品图片">
          <el-input type="textarea" v-model="form.img" placeholder="请输入图片路径"></el-input>
        </el-form-item>

        <el-form-item label="奖品描述">
          <el-input type="textarea" v-model="form.description" placeholder="请输入奖品描述"></el-input>
        </el-form-item>

        <el-form-item label="奖品价值">
          <el-input v-model="form.value" type="number" placeholder="请输入奖品价值"></el-input>
        </el-form-item>

        <el-form-item label="奖品库存">
          <el-input v-model="form.stock" type="number" placeholder="请输入奖品库存"></el-input>
        </el-form-item>

        <el-form-item label="奖品状态">
          <el-select v-model="form.status">
            <el-option label="禁用" value="0"></el-option>
            <el-option label="启用" value="1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button @click="goBack">返回</el-button>
          <el-button type="primary" @click="submitForm">提交</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      form: {
        name: '',
        img: '',
        description: '',
        value: '',
        stock: '',
        status: '1'  // 默认为'上架'
      }
    };
  },

  methods: {
    goBack(){
      this.$router.push("/home/prize-list")
    },


    submitForm() {
      axios.post("http://localhost:9090/draw/prize/save", this.form, {
        headers: {
          'Content-Type': 'application/json'
        }
      }).then(
          response => {
            console.log(response)

            if (response.data.state==0){
              this.$message.success("新增成功");
              this.$router.push("/home/prize-list")
            }else {
              this.$message.error("新增失败")
            }
          }
      )
    }
  }
}
</script>

<style scoped>
.prize-form-container {

}

.breadcrumb {
  margin-bottom: 20px;
}

.form-card {

  padding: 20px;
}

.prize-form {
  width: 40%;
  margin-top: 20px;
}


</style>